package com.ml.mall.api.analytics;

import com.ml.mall.api.BaseController;
import com.ml.mall.bean.base.ApiRestResult;
import com.ml.mall.bean.req.*;

import com.ml.mall.bean.req.admin.AdminIndustryQueryOneReq;
import com.ml.mall.bean.req.admin.AdminIndustryQueryPageReq;
import com.ml.mall.bean.req.admin.AdminIndustrySupplierQueryPageReq;
import com.ml.mall.bean.req.admin.category.AdminCategoryQueryOneReq;
import com.ml.mall.bean.req.admin.category.AdminCategoryQueryPageReq;
import com.ml.mall.bean.req.admin.category.CategoryQuerySubcategoryTotalfeeReq;
import com.ml.mall.bean.req.admin.coupon.CouponQueryOneReq;
import com.ml.mall.bean.req.admin.supplier.SupplierQueryOneByCategoryReq;
import com.ml.mall.bean.req.admin.supplier.SupplierQueryOneByPurchaseReq;
import com.ml.mall.bean.req.admin.supplier.SupplierQueryOneReq;
import com.ml.mall.bean.req.admin.supplier.SupplierQueryPageReq;
import com.ml.mall.bean.req.admin.variant.VariantQueryOneReq;
import com.ml.mall.bean.req.admin.variant.VariantQueryPageReq;
import com.ml.mall.bean.req.admin.purchase.PurchaseQueryOneReq;
import com.ml.mall.bean.req.admin.purchase.PurchaseQueryReportPageReq;
import com.ml.mall.bean.req.admin.purchase.PurchaseQuerySpentCategoryReq;
import com.ml.mall.consts.CommonConsts;
import com.ml.mall.consts.PermissionConst;
import com.ml.mall.consts.UserRoleTypeConsts;
import com.ml.mall.entity.sys.SysUser;
import com.ml.mall.security.JwtUtil;
import com.ml.mall.service.AnalyticsAdminService;
import com.ml.mall.utils.DateUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * Created by kyyang on 2021/6/8 21:39
 */
@Api(tags = "【analytics】管理员")
@RestController
@RequestMapping("/admin")
@Slf4j
public class AnalyticsAdminController extends BaseController {



    @Autowired
    private AnalyticsAdminService analyticsAdminService;


    @RequestMapping(method = RequestMethod.POST, path = "/overview")
    @ApiOperation("管理员面板")
//    @RequiresPermissions(PermissionConst.ADMIN_OVERVIEW)
    public ApiRestResult adminOverview(@Valid @RequestBody BaseDateRangeReq req) throws Exception {
        int dateDiff = DateUtils.getDateDiff(req.getTimeBegin(), req.getTimeEnd());
        if(CommonConsts.MAX_REPORT_DIFF_DAYS < dateDiff){
            log.error("当前时间范围天数为：[{}],超过上限 {} 天",dateDiff, CommonConsts.MAX_REPORT_DIFF_DAYS);
            return ApiRestResult.err("Jarak masa yang dipilih：["+dateDiff+"],telah melebihi "+ CommonConsts.MAX_REPORT_DIFF_DAYS +" hari","400");
        }
        return ApiRestResult.ok(analyticsAdminService.getAdminOverview(req));
    }

    @RequestMapping(method = RequestMethod.POST, path = "/purchaser")
    @ApiOperation("管理员订单报告")
//  @RequiresPermissions(PermissionConst.ADMIN_PURCHASE)
    public ApiRestResult adminPurchase(@Valid @RequestBody BaseDateRangeReq req) throws Exception {
        int dateDiff = DateUtils.getDateDiff(req.getTimeBegin(), req.getTimeEnd());
        if(CommonConsts.MAX_REPORT_DIFF_DAYS<dateDiff){
            log.error("当前时间范围天数为：[{}],超过上限 {} 天", dateDiff, CommonConsts.MAX_REPORT_DIFF_DAYS);
            return ApiRestResult.err("Jarak masa yang dipilih：["+dateDiff+"],telah melebihi 30 hari","400");
        }
        return ApiRestResult.ok(analyticsAdminService.getAdminPurchase(req));
    }


    @RequestMapping(method = RequestMethod.POST, path = "/purchaser/query_report_page")
    @ApiOperation("买家消费金额分页查询")
//    @RequiresPermissions(PermissionConst.ADMIN_PURCHASE_QUERY_REPORT_PAGE)
    public ApiRestResult adminPurchaseQueryReportPage(@Valid @RequestBody PurchaseQueryReportPageReq req) throws Exception {
        int dateDiff = DateUtils.getDateDiff(req.getTimeBegin(), req.getTimeEnd());
        if(CommonConsts.MAX_REPORT_DIFF_DAYS<dateDiff){
            log.error("当前时间范围天数为：[{}],超过上限 {} 天",dateDiff, CommonConsts.MAX_REPORT_DIFF_DAYS);
            return ApiRestResult.err("Jarak masa yang dipilih：["+dateDiff+"],telah melebihi 30 hari","400");
        }
        return ApiRestResult.ok(analyticsAdminService.adminPurchaseQueryReportPage(req, null));
    }

    @RequestMapping(method = RequestMethod.POST, path = "/purchaser/detail")
    @ApiOperation("买家时间范围内交易详情")
//    @RequiresPermissions(PermissionConst.ADMIN_PURCHASE_DETAIL)
    public ApiRestResult adminPurchaseQueryOneDetail(@Valid @RequestBody PurchaseQueryOneReq req) throws Exception {
        int dateDiff = DateUtils.getDateDiff(req.getTimeBegin(), req.getTimeEnd());
        if(CommonConsts.MAX_REPORT_DIFF_DAYS<dateDiff){
            log.error("当前时间范围天数为：[{}],超过上限 {} 天",dateDiff, CommonConsts.MAX_REPORT_DIFF_DAYS);
            return ApiRestResult.err("Jarak masa yang dipilih：["+dateDiff+"],telah melebihi 30 hari","400");
        }
        return ApiRestResult.ok(analyticsAdminService.adminPurchaseQueryOneDetail(req));
    }


    @RequestMapping(method = RequestMethod.POST, path = "/purchaser/spent_by_category")
    @ApiOperation("买家消费目录：分页查询")
//    @RequiresPermissions(PermissionConst.ADMIN_PURCHASER_SPENT_BY_CATEGORY)
    public ApiRestResult adminPurchaseSpentByCategory(@Valid @RequestBody PurchaseQuerySpentCategoryReq req) throws Exception {
        int dateDiff = DateUtils.getDateDiff(req.getTimeBegin(), req.getTimeEnd());
        if(CommonConsts.MAX_REPORT_DIFF_DAYS<dateDiff){
            log.error("当前时间范围天数为：[{}],超过上限 {} 天",dateDiff, CommonConsts.MAX_REPORT_DIFF_DAYS);
            return ApiRestResult.err("Jarak masa yang dipilih：["+dateDiff+"],telah melebihi 30 hari","400");
        }
        return ApiRestResult.ok(analyticsAdminService.adminPurchaseSpentByCategory(req));
    }

    @RequestMapping(method = RequestMethod.POST, path = "/purchaser/spent_by_supplier")
    @ApiOperation("买家消费卖家：分页查询")
//    @RequiresPermissions(PermissionConst.ADMIN_PURCHASE_SPENT_BY_SUPPLIER)
    public ApiRestResult adminPurchaseSpentBySupplier(@Valid @RequestBody PurchaseQuerySpentCategoryReq req) throws Exception {
        int dateDiff = DateUtils.getDateDiff(req.getTimeBegin(), req.getTimeEnd());
        if(CommonConsts.MAX_REPORT_DIFF_DAYS<dateDiff){
            log.error("当前时间范围天数为：[{}],超过上限 {} 天",dateDiff, CommonConsts.MAX_REPORT_DIFF_DAYS);
            return ApiRestResult.err("Jarak masa yang dipilih：["+dateDiff+"],telah melebihi 30 hari","400");
        }
        return ApiRestResult.ok(analyticsAdminService.adminPurchaseSpentBySupplier(req));
    }

    @RequestMapping(method = RequestMethod.POST, path = "/purchaser/spent_by_product")
    @ApiOperation("买家消费产品：分页查询")
//    @RequiresPermissions(PermissionConst.ADMIN_PURCHASE_SPENT_BY_PRODUCT)
    public ApiRestResult adminPurchaseSpentByProduct(@Valid @RequestBody PurchaseQuerySpentCategoryReq req) throws Exception {
        int dateDiff = DateUtils.getDateDiff(req.getTimeBegin(), req.getTimeEnd());
        if(CommonConsts.MAX_REPORT_DIFF_DAYS<dateDiff){
            log.error("当前时间范围天数为：[{}],超过上限 {} 天",dateDiff, CommonConsts.MAX_REPORT_DIFF_DAYS);
            return ApiRestResult.err("Jarak masa yang dipilih：["+dateDiff+"],telah melebihi 30 hari","400");
        }
        return ApiRestResult.ok(analyticsAdminService.adminPurchaseSpentByProduct(req));
    }

    @RequestMapping(method = RequestMethod.POST, path = "/industry/query_top")
    @ApiOperation("industry:前10 每日数据")
//    @RequiresPermissions(PermissionConst.ADMIN_INDUSTRY_QUERY_TOP)
    public ApiRestResult adminIndustryQueryTop(@Valid @RequestBody BaseDateRangeReq req) throws Exception {
        int dateDiff = DateUtils.getDateDiff(req.getTimeBegin(), req.getTimeEnd());
        if(CommonConsts.MAX_REPORT_DIFF_DAYS<dateDiff){
            log.error("当前时间范围天数为：[{}],超过上限 {} 天",dateDiff, CommonConsts.MAX_REPORT_DIFF_DAYS);
            return ApiRestResult.err("Jarak masa yang dipilih：["+dateDiff+"],telah melebihi 30 hari","400");
        }
        return ApiRestResult.ok(analyticsAdminService.adminIndustryQueryTop(req));
    }

    @RequestMapping(method = RequestMethod.POST, path = "/industry/query_page")
    @ApiOperation("industry：分页查询")
//    @RequiresPermissions(PermissionConst.ADMIN_INDUSTRY_QUERY_PAGE)
    public ApiRestResult adminIndustryQueryPage(@Valid @RequestBody AdminIndustryQueryPageReq req) throws Exception {
        int dateDiff = DateUtils.getDateDiff(req.getTimeBegin(), req.getTimeEnd());
        if(CommonConsts.MAX_REPORT_DIFF_DAYS<dateDiff){
            log.error("当前时间范围天数为：[{}],超过上限 {} 天",dateDiff, CommonConsts.MAX_REPORT_DIFF_DAYS);
            return ApiRestResult.err("Jarak masa yang dipilih：["+dateDiff+"],telah melebihi 30 hari","400");
        }
        return ApiRestResult.ok(analyticsAdminService.adminIndustryQueryPage(req));
    }

    @RequestMapping(method = RequestMethod.POST, path = "/industry/query_one")
    @ApiOperation("查询某一个产业的汇总明细")
//    @RequiresPermissions(PermissionConst.ADMIN_INDUSTRY_QUERY_ONE)
    public ApiRestResult adminIndustryQueryOne(@Valid @RequestBody AdminIndustryQueryOneReq req) throws Exception {
        int dateDiff = DateUtils.getDateDiff(req.getTimeBegin(), req.getTimeEnd());
        if(CommonConsts.MAX_REPORT_DIFF_DAYS<dateDiff){
            log.error("当前时间范围天数为：[{}],超过上限 {} 天",dateDiff, CommonConsts.MAX_REPORT_DIFF_DAYS);
            return ApiRestResult.err("Jarak masa yang dipilih：["+dateDiff+"],telah melebihi 30 hari","400");
        }
        return ApiRestResult.ok(analyticsAdminService.adminIndustryQueryOne(req));
    }


    @RequestMapping(method = RequestMethod.POST, path = "/category/query_top")
    @ApiOperation("管理员查询目录报告：前10名")
//    @RequiresPermissions(PermissionConst.ADMIN_CATEGORY_QUERY_TOP)
    public ApiRestResult adminCategoryQueryTop(@Valid @RequestBody BaseDateRangeReq req) throws Exception {
        int dateDiff = DateUtils.getDateDiff(req.getTimeBegin(), req.getTimeEnd());
        if(CommonConsts.MAX_REPORT_DIFF_DAYS<dateDiff){
            log.error("当前时间范围天数为：[{}],超过上限 {} 天",dateDiff, CommonConsts.MAX_REPORT_DIFF_DAYS);
            return ApiRestResult.err("Jarak masa yang dipilih：["+dateDiff+"],telah melebihi 30 hari","400");
        }
        return ApiRestResult.ok(analyticsAdminService.adminCategoryQueryTop(req, null));
    }

    @RequestMapping(method = RequestMethod.POST, path = "/category/query_page")
    @ApiOperation("管理员分页查询目录报告")
//    @RequiresPermissions(PermissionConst.ADMIN_CATEGORY_QUERY_PAGE)
    public ApiRestResult adminCategoryQueryPage(@Valid @RequestBody AdminCategoryQueryPageReq req) throws Exception {
        int dateDiff = DateUtils.getDateDiff(req.getTimeBegin(), req.getTimeEnd());
        if(CommonConsts.MAX_REPORT_DIFF_DAYS<dateDiff){
            log.error("当前时间范围天数为：[{}],超过上限 {} 天",dateDiff, CommonConsts.MAX_REPORT_DIFF_DAYS);
            return ApiRestResult.err("Jarak masa yang dipilih：["+dateDiff+"],telah melebihi 30 hari","400");
        }
        return ApiRestResult.ok(analyticsAdminService.adminCategoryQueryPage(req, null));
    }

    @RequestMapping(method = RequestMethod.POST, path = "/category/query_one")
    @ApiOperation("查询某一目录详细：每日详细")
//    @RequiresPermissions(PermissionConst.ADMIN_CATEGORY_QUERY_ONE)
    public ApiRestResult adminCategoryQueryOne(@Valid @RequestBody AdminCategoryQueryOneReq req) throws Exception {
        int dateDiff = DateUtils.getDateDiff(req.getTimeBegin(), req.getTimeEnd());
        SysUser currentUser = JwtUtil.getCurrentUser();
        Long supplierId = UserRoleTypeConsts.ROLE_TYPE_1 == currentUser.getRoleType() ? null : currentUser.getCompanyId();
        if(CommonConsts.MAX_REPORT_DIFF_DAYS<dateDiff){
            log.error("当前时间范围天数为：[{}],超过上限 {} 天",dateDiff, CommonConsts.MAX_REPORT_DIFF_DAYS);
            return ApiRestResult.err("Jarak masa yang dipilih：["+dateDiff+"],telah melebihi 30 hari","400");
        }
        return ApiRestResult.ok(analyticsAdminService.adminCategoryQueryOne(req, supplierId));
    }


    @RequestMapping(method = RequestMethod.POST, path = "/industry/supplier/query_page")
    @ApiOperation("行业下产品属供销商 销售额查询")
//    @RequiresPermissions(PermissionConst.ADMIN_INDUSTRY_SUPPLIER_QUERY_PAGE)
    public ApiRestResult admiIndustrySupplierQueryPage(@Valid @RequestBody AdminIndustrySupplierQueryPageReq req) throws Exception {
        int dateDiff = DateUtils.getDateDiff(req.getTimeBegin(), req.getTimeEnd());
        if(CommonConsts.MAX_REPORT_DIFF_DAYS<dateDiff){
            log.error("当前时间范围天数为：[{}],超过上限 {} 天",dateDiff, CommonConsts.MAX_REPORT_DIFF_DAYS);
            return ApiRestResult.err("Jarak masa yang dipilih：["+dateDiff+"],telah melebihi 30 hari","400");
        }
        return ApiRestResult.ok(analyticsAdminService.admiIndustrySupplierQueryPage(req));
    }


    @RequestMapping(method = RequestMethod.POST, path = "/category/query_report_page")
    @ApiOperation("category：report_page")
//    @RequiresPermissions(PermissionConst.ADMIN_CATEGORY_QUERY_REPORT_PAGE)
    public ApiRestResult adminCategoryQueryReportPage(@Valid @RequestBody AdminCategoryQueryPageReq req) throws Exception {
        int dateDiff = DateUtils.getDateDiff(req.getTimeBegin(), req.getTimeEnd());
        if(CommonConsts.MAX_REPORT_DIFF_DAYS<dateDiff){
            log.error("当前时间范围天数为：[{}],超过上限 {} 天",dateDiff, CommonConsts.MAX_REPORT_DIFF_DAYS);
            return ApiRestResult.err("Jarak masa yang dipilih：["+dateDiff+"],telah melebihi 30 hari","400");
        }
        return ApiRestResult.ok(analyticsAdminService.adminCategoryQueryReportPage(req, null));
    }


    @RequestMapping(method = RequestMethod.POST, path = "/category/query_one_detail_sales_supplier")
    @ApiOperation("查询某一个目录商家销售额分页：此处为：一级目录")
//    @RequiresPermissions(PermissionConst.ADMIN_CATEGORY_QUERY_ONE_DETAIL_SALES_SUPPLIER)
    public ApiRestResult adminCategoryQueryOneDetailSalesSupplier(@Valid @RequestBody AdminIndustrySupplierQueryPageReq req) throws Exception {
        int dateDiff = DateUtils.getDateDiff(req.getTimeBegin(), req.getTimeEnd());
        if(CommonConsts.MAX_REPORT_DIFF_DAYS<dateDiff){
            log.error("当前时间范围天数为：[{}],超过上限 {} 天",dateDiff, CommonConsts.MAX_REPORT_DIFF_DAYS);
            return ApiRestResult.err("Jarak masa yang dipilih：["+dateDiff+"],telah melebihi 30 hari","400");
        }
        return ApiRestResult.ok(analyticsAdminService.admiCategoryQueryOneDetailSalesSupplier(req));
    }

    @RequestMapping(method = RequestMethod.POST, path = "/category/query_subcategory_totalfee")
    @ApiOperation("查询某一个目录子目录的销售额；根目录查一级；一级查二级；找parentId 等于 传入id的子目录就行了")
//    @RequiresPermissions(PermissionConst.ADMIN_CATEGORY_QUERY_SUBCATEGORY_TOTALFEE)
    public ApiRestResult adminCategoryQuerySubcategoryTotalfee(@Valid @RequestBody CategoryQuerySubcategoryTotalfeeReq req) throws Exception {
        int dateDiff = DateUtils.getDateDiff(req.getTimeBegin(), req.getTimeEnd());
        if(CommonConsts.MAX_REPORT_DIFF_DAYS<dateDiff){
            log.error("当前时间范围天数为：[{}],超过上限 {} 天",dateDiff, CommonConsts.MAX_REPORT_DIFF_DAYS);
            return ApiRestResult.err("Jarak masa yang dipilih：["+dateDiff+"],telah melebihi 30 hari","400");
        }
        return ApiRestResult.ok(analyticsAdminService.adminCategoryQuerySubcategoryTotalfee(req));
    }


    @RequestMapping(method = RequestMethod.POST, path = "/variant/query_top")
    @ApiOperation("产品变体查询分析报告：前10名")
//    @RequiresPermissions(PermissionConst.ADMIN_VARIANT_QUERY_TOP)
    public ApiRestResult adminVariantQueryTop(@Valid @RequestBody BaseDateRangeReq req) throws Exception {
        int dateDiff = DateUtils.getDateDiff(req.getTimeBegin(), req.getTimeEnd());
        if(CommonConsts.MAX_REPORT_DIFF_DAYS<dateDiff){
            log.error("当前时间范围天数为：[{}],超过上限 {} 天",dateDiff, CommonConsts.MAX_REPORT_DIFF_DAYS);
            return ApiRestResult.err("Jarak masa yang dipilih：["+dateDiff+"],telah melebihi 30 hari","400");
        }
        return ApiRestResult.ok(analyticsAdminService.adminVariantQueryTop(req, null));
    }


    @RequestMapping(method = RequestMethod.POST, path = "/variant/query_one")
    @ApiOperation("查询某一个变体的时间范围内的销售报告")
//    @RequiresPermissions(PermissionConst.ADMIN_VARIANT_QUERY_ONE)
    public ApiRestResult adminVariantQueryOne(@Valid @RequestBody VariantQueryOneReq req) throws Exception {
        int dateDiff = DateUtils.getDateDiff(req.getTimeBegin(), req.getTimeEnd());
        if(CommonConsts.MAX_REPORT_DIFF_DAYS<dateDiff){
            log.error("当前时间范围天数为：[{}],超过上限 {} 天",dateDiff, CommonConsts.MAX_REPORT_DIFF_DAYS);
            return ApiRestResult.err("Jarak masa yang dipilih：["+dateDiff+"],telah melebihi 30 hari","400");
        }
        return ApiRestResult.ok(analyticsAdminService.adminVariantQueryOne(req, null));
    }

    @RequestMapping(method = RequestMethod.POST, path = "/variant/query_page")
    @ApiOperation("分页查询变体汇总")
//    @RequiresPermissions(PermissionConst.ADMIN_VARIANT_QUERY_PAGE)
    public ApiRestResult adminVariantQueryPage(@Valid @RequestBody VariantQueryPageReq req) throws Exception {
        int dateDiff = DateUtils.getDateDiff(req.getTimeBegin(), req.getTimeEnd());
        if(CommonConsts.MAX_REPORT_DIFF_DAYS<dateDiff){
            log.error("当前时间范围天数为：[{}],超过上限 {} 天",dateDiff, CommonConsts.MAX_REPORT_DIFF_DAYS);
            return ApiRestResult.err("Jarak masa yang dipilih：["+dateDiff+"],telah melebihi 30 hari","400");
        }
        return ApiRestResult.ok(analyticsAdminService.adminVariantQueryPage(req, null));
    }

    @RequestMapping(method = RequestMethod.POST, path = "/supplier/query_report")
    @ApiOperation("查询供应商统计")
//    @RequiresPermissions(PermissionConst.ADMIN_SUPPLIER_QUERY_REPORT)
    public ApiRestResult adminSupplierQueryReport(@Valid @RequestBody BaseDateRangeReq req) throws Exception {
        int dateDiff = DateUtils.getDateDiff(req.getTimeBegin(), req.getTimeEnd());
        if(CommonConsts.MAX_REPORT_DIFF_DAYS<dateDiff){
            log.error("当前时间范围天数为：[{}],超过上限 {} 天",dateDiff, CommonConsts.MAX_REPORT_DIFF_DAYS);
            return ApiRestResult.err("Jarak masa yang dipilih：["+dateDiff+"],telah melebihi 30 hari","400");
        }
        return ApiRestResult.ok(analyticsAdminService.adminSupplierQueryReport(req));
    }

    @RequestMapping(method = RequestMethod.POST, path = "/supplier/query_page")
    @ApiOperation("分页查询供应商统计")
//    @RequiresPermissions(PermissionConst.ADMIN_SUPPLIER_QUERY_PAGE)
    public ApiRestResult adminSupplierQueryPage(@Valid @RequestBody SupplierQueryPageReq req) throws Exception {
        int dateDiff = DateUtils.getDateDiff(req.getTimeBegin(), req.getTimeEnd());
        if(CommonConsts.MAX_REPORT_DIFF_DAYS<dateDiff){
            log.error("当前时间范围天数为：[{}],超过上限 {} 天",dateDiff, CommonConsts.MAX_REPORT_DIFF_DAYS);
            return ApiRestResult.err("Jarak masa yang dipilih：["+dateDiff+"],telah melebihi 30 hari","400");
        }
        return ApiRestResult.ok(analyticsAdminService.adminSupplierQueryPage(req));
    }

    @RequestMapping(method = RequestMethod.POST, path = "/supplier/query_one")
    @ApiOperation("某一供应商报告")
//    @RequiresPermissions(PermissionConst.ADMIN_SUPPLIER_QUERY_ONE)
    public ApiRestResult adminSupplierQueryOne(@Valid @RequestBody SupplierQueryOneReq req) throws Exception {
        int dateDiff = DateUtils.getDateDiff(req.getTimeBegin(), req.getTimeEnd());
        if(CommonConsts.MAX_REPORT_DIFF_DAYS<dateDiff){
            log.error("当前时间范围天数为：[{}],超过上限 {} 天",dateDiff, CommonConsts.MAX_REPORT_DIFF_DAYS);
            return ApiRestResult.err("Jarak masa yang dipilih：["+dateDiff+"],telah melebihi 30 hari","400");
        }
        return ApiRestResult.ok(analyticsAdminService.adminSupplierQueryOne(req));
    }

    @RequestMapping(method = RequestMethod.POST, path = "/supplier/query_one_by_category")
    @ApiOperation("查询某一个公司 时间范围内 目录销售额")
//    @RequiresPermissions(PermissionConst.ADMIN_SUPPLIER_QUERY_ONE_BY_CATEGORY)
    public ApiRestResult adminSupplierQueryOneByCategory(@Valid @RequestBody SupplierQueryOneByCategoryReq req) throws Exception {
        int dateDiff = DateUtils.getDateDiff(req.getTimeBegin(), req.getTimeEnd());
        if(CommonConsts.MAX_REPORT_DIFF_DAYS<dateDiff){
            log.error("当前时间范围天数为：[{}],超过上限 {} 天",dateDiff, CommonConsts.MAX_REPORT_DIFF_DAYS);
            return ApiRestResult.err("Jarak masa yang dipilih：["+dateDiff+"],telah melebihi 30 hari","400");
        }
        return ApiRestResult.ok(analyticsAdminService.adminSupplierQueryOneByCategory(req));
    }

    @RequestMapping(method = RequestMethod.POST, path = "/supplier/query_one_by_purchase")
    @ApiOperation("某卖家下买家消费分页")
//    @RequiresPermissions(PermissionConst.ADMIN_SUPPLIER_QUERY_ONE_BY_PURCHASE)
    public ApiRestResult adminSupplierQueryOneByPurchasePage(@Valid @RequestBody SupplierQueryOneByPurchaseReq req) throws Exception {
        int dateDiff = DateUtils.getDateDiff(req.getTimeBegin(), req.getTimeEnd());
        if(CommonConsts.MAX_REPORT_DIFF_DAYS<dateDiff){
            log.error("当前时间范围天数为：[{}],超过上限 {} 天",dateDiff, CommonConsts.MAX_REPORT_DIFF_DAYS);
            return ApiRestResult.err("Jarak masa yang dipilih：["+dateDiff+"],telah melebihi 30 hari","400");
        }
        return ApiRestResult.ok(analyticsAdminService.adminSupplierQueryOneByPurchasePage(req));
    }


    @RequestMapping(method = RequestMethod.POST, path = "/coupon/query_one")
    @ApiOperation("某张券消费情况")
//    @RequiresPermissions(PermissionConst.ADMIN_COUPON_QUERY_ONE)
    public ApiRestResult adminCouponQueryOne(@Valid @RequestBody CouponQueryOneReq req) throws Exception {
        int dateDiff = DateUtils.getDateDiff(req.getTimeBegin(), req.getTimeEnd());
        if(CommonConsts.MAX_REPORT_DIFF_DAYS<dateDiff){
            log.error("当前时间范围天数为：[{}],超过上限 {} 天",dateDiff, CommonConsts.MAX_REPORT_DIFF_DAYS);
            return ApiRestResult.err("Jarak masa yang dipilih：["+dateDiff+"],telah melebihi 30 hari","400");
        }
        return ApiRestResult.ok(analyticsAdminService.adminCouponQueryOne(req));
    }


}
